package com.shmilyou.dissertationmanagement.biz;
/* Created with 岂止是一丝涟漪     530060499@qq.com    2019/3/7 */

import com.shmilyou.dissertationmanagement.domain.ThesisType;
import com.shmilyou.dissertationmanagement.repository.ThesisTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ThesisTypeService {

    private final ThesisTypeRepository thesisTypeRepository;

    @Autowired
    public ThesisTypeService(ThesisTypeRepository thesisTypeRepository) {
        this.thesisTypeRepository = thesisTypeRepository;
    }

    public ThesisType queryById(Integer id) {
        Optional<ThesisType> byId = thesisTypeRepository.findById(id);
        return byId.orElse(null);
    }

    public List<ThesisType> queryAll() {
        return thesisTypeRepository.findAllByDel(0);
    }

    public ThesisType update(ThesisType entity) {
        return thesisTypeRepository.save(entity);
    }

    public ThesisType delete(ThesisType entity) {
        entity.setDel(1);
        return thesisTypeRepository.save(entity);
    }

    public ThesisType save(ThesisType entity) {
        return thesisTypeRepository.save(entity);
    }
}
